package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理相关接口")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation(value = "分页查询护理项目", notes = "传入name，pageNum，pageSize，status")
    public ResponseResult<PageResponse<NursingProjectVo>> pageNursingProject(@RequestParam(required = false) String name,
                                                                             @RequestParam(defaultValue = "1") Integer pageNum,
                                                                             @RequestParam(defaultValue = "10") Integer pageSize,
                                                                             @RequestParam(required = false) Integer status) {
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.pageNursingProject(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    @PostMapping
    @ApiModelProperty(value = "添加护理项目", notes = "传入护理项目对象")
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }
    @GetMapping("/{id}")
    @ApiModelProperty(value = "根据id查询护理项目", notes = "传入id")
    public ResponseResult<NursingProjectVo> getNursingProjectById(@PathVariable Long id){
       NursingProjectVo nursingProjectVo = nursingProjectService.getNursingProjectById(id);
        return success(nursingProjectVo);
    }
    @PutMapping
    @ApiModelProperty(value = "修改护理项目", notes = "传入护理项目对象")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiModelProperty(value = "修改护理项目状态", notes = "传入id和状态")
    public ResponseResult updateStatus(@PathVariable(required = true) Long id,
                                       @PathVariable(required = true) Integer status){
        nursingProjectService.updateStatus(id,status);
        return success();
    }
    @DeleteMapping("/{id}")
    @ApiModelProperty(value = "删除护理项目", notes = "传入id")
    public ResponseResult deleteNursingProject(@PathVariable Long id){
        nursingProjectService.deleteNursingProject(id);
        return success();
    }
    @GetMapping("/all")
    @ApiModelProperty(value = "获取护理项目列表")
    public ResponseResult<List<NursingProjectVo>> getNursingProjectList(){
       List<NursingProjectVo>nursingProjectVos = nursingProjectService.getNursingProjectList();
        return success(nursingProjectVos);
    }

}
